package com.erp.module.jiJian

import android.content.Context
import android.util.Log
import com.erp.bean.JijianBean
import com.erp.bean.Twostringbean
import com.erp.Interface.OnUserDataInterface
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import com.erp.util.Myutil
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import java.util.*
import kotlin.math.log

/**
 * Created by Administrator on 2019/3/19/019.
 * 作者：刘洋
 */
class IJiJianP(val V : JiJianContract.JiJianView, val context : Context,var list : MutableList<JijianBean>) : BasePullP(),JiJianContract.JiJianP{
    val md : JiJianContract.JiJianMP= JiJianModel()
    var searchParams: MutableList<Twostringbean> = ArrayList()
    init {
        PullV=V
    }
    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        md.getjijian(context, page, pagesize, searchParams,onUserDataInterface)
    }

    override fun jsondata(data: String?) {

        if(data==null){
            return
        }
        Log.d("jsondata",data)
        return
        try {
            val js = JSONArray(data)
             for (i in 0 until js.length()) {
                val jo = js.get(i) as JSONObject
                val jijianBean = JijianBean()
                jijianBean.ws_name = JsonUtil.getvolue(jo, "ws_name")
                jijianBean.pw_project = JsonUtil.getvolue(jo, "pw_project")
                jijianBean.jishu = JsonUtil.getvolue(jo, "jishu")
                val membersBeanList = java.util.ArrayList<JijianBean.MembersBean>()
                val js1 = JsonUtil.getjsvolue(jo, "members")
                for (j in 0 until js1!!.length()) {
                    val jo1 = js1.get(j) as JSONObject
                    val membersBean = JijianBean.MembersBean()
                    membersBean.wu_name = JsonUtil.getvolue(jo1, "wu_name")
                    membersBean.work_number = JsonUtil.getvolue(jo1, "work_number")
                    membersBeanList.add(membersBean)
                }
                jijianBean.members = membersBeanList
                list.add(jijianBean)
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }

    override fun listClean() {
        list.clear()
    }

    override fun sousuo(searchParams: ArrayList<Twostringbean>) {
        this.searchParams=searchParams
    }
}